From 3c5b58921d3f2c0acf24084af112574b2ef0fc67 Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 16 Jan 2005 23:22:19 +0000 Subject: [PATCH] Bust UTF-8 encoded waypoint names and comments down to ASCII for Mapsend. --- gpsbabel/mapsend.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/gpsbabel/mapsend.c b/gpsbabel/mapsend.c index c7e24feba..1bf106af7 100644 --- a/gpsbabel/mapsend.c +++ b/gpsbabel/mapsend.c @@ -318,19 +318,41 @@ mapsend_waypt_pr(const waypoint *waypointp) const char *sn = global_opts.synthesize_shortnames ? mkshort(mkshort_handle, waypointp->description) : waypointp->shortname; + char *tmp; - c = sn ? strlen(sn) : 0; + /* + * The format spec doesn't call out the character set of waypoint + * name and description. Empirically, we can see that it's 8859-1, + * but if we create mapsend files containing those, Mapsend becomes + * grumpy uploading the resulting waypoints and being unable to deal + * with the resulting comm errors. + * + * Ironically, our own Magellan serial module strips the "naughty" + * characters, keeping it more in definition with their own serial + * spec. :-) + * + * So we just decompose the utf8 strings to ascii before stuffing + * them into the Mapsend file. + */ + + tmp = str_utf8_to_ascii(sn); + c = tmp ? strlen(tmp) : 0; fwrite(&c, 1, 1, mapsend_file_out); - fwrite(sn, c, 1, mapsend_file_out); + fwrite(tmp, c, 1, mapsend_file_out); + if (tmp) + xfree(tmp); - if (waypointp->description) - c = strlen(waypointp->description); + tmp = str_utf8_to_ascii(waypointp->description); + if (tmp) + c = strlen(tmp); else c = 0; if (c > 30) c = 30; fwrite(&c, 1, 1, mapsend_file_out); - fwrite(waypointp->description, c, 1, mapsend_file_out); + fwrite(tmp, c, 1, mapsend_file_out); + if (tmp) + xfree(tmp); /* #, icon, status */ n = ++cnt; -- 2.30.2